#include "HorizontalCardinal.h"

#include "CatanClassContractException.h"

namespace catan
{

/*static*/ std::vector<HorizontalCardinal::Enum_HorizontalCardinal> HorizontalCardinal::vectorOfPossibleEnumValues;
/*static*/ std::vector<HorizontalCardinal::Enum_HorizontalCardinal> HorizontalCardinal::vectorOfReducedPossibleEnumValues;

/*static*/ const std::vector<HorizontalCardinal::Enum_HorizontalCardinal> &HorizontalCardinal::getVectorOfPossibleEnumValues()
{
	if (vectorOfPossibleEnumValues.empty())
	{
		vectorOfPossibleEnumValues.push_back(HORIZONTAL_CR);
		vectorOfPossibleEnumValues.push_back(HORIZONTAL_TR);
		vectorOfPossibleEnumValues.push_back(HORIZONTAL_TL);
		vectorOfPossibleEnumValues.push_back(HORIZONTAL_CL);
		vectorOfPossibleEnumValues.push_back(HORIZONTAL_BL);
		vectorOfPossibleEnumValues.push_back(HORIZONTAL_BR);
	}
	return vectorOfPossibleEnumValues;
}

/*static*/ const std::vector<HorizontalCardinal::Enum_HorizontalCardinal> &HorizontalCardinal::getVectorOfReducedPossibleEnumValues()
{
	if (vectorOfReducedPossibleEnumValues.empty())
	{
		vectorOfReducedPossibleEnumValues.push_back(HORIZONTAL_CR);
		vectorOfReducedPossibleEnumValues.push_back(HORIZONTAL_CL);
	}
	return vectorOfReducedPossibleEnumValues;
}

/*static*/ bool HorizontalCardinal::canInit(Enum_HorizontalCardinal enumCardinal)
{
	const std::vector<Enum_HorizontalCardinal> enumValues = HorizontalCardinal::getVectorOfPossibleEnumValues();
	for (std::vector<Enum_HorizontalCardinal>::const_iterator enumValueIterator = enumValues.begin(); enumValueIterator != enumValues.end(); ++enumValueIterator)
	{
		if (enumCardinal == *enumValueIterator)
		{
			return true;
		}
	}
	return false;
}

/*explicit*/ HorizontalCardinal::HorizontalCardinal(Enum_HorizontalCardinal enumCardinal): enumCardinal(enumCardinal)
{
	if (!HorizontalCardinal::canInit(enumCardinal))
	{
		throw CatanClassContractException(__FILE__, __LINE__, "HorizontalCardinal::canInit(...) with constructor arguments should be true before creating instance.");
	}
}

HorizontalCardinal::Enum_HorizontalCardinal HorizontalCardinal::getEnum() const
{
	return enumCardinal;
}

bool HorizontalCardinal::operator==(const HorizontalCardinal &other) const
{
	return enumCardinal == other.enumCardinal;
}

bool HorizontalCardinal::operator<(const HorizontalCardinal &other) const
{
	return enumCardinal < other.enumCardinal;
}

HorizontalCardinal& HorizontalCardinal::operator=(const HorizontalCardinal& other)
{
    if (this != &other)
    {
        enumCardinal = other.enumCardinal;
    }
    return *this;	
}

}